import java.util.Arrays;

class Solution6 {
    public static int[] missingTwo(int[] nums) {
        int j = 0,tmp = 0;
        for(int i = 1; i <= nums.length+2; i++) {
            if(j < nums.length) {
                tmp  ^=  nums[j];
                j++;
            }
            tmp ^= i;

        }
        int x = 0;
        for(int i = 0; i < 32; i++) {
            if(((tmp >> i) & 1) == 1) {
                x = i;
                break;
            }
        }
        int[] ret = new int[2];
        int x1 = 0;
        int x2 = 0;
        int k = 0;
        for(int i = 1; i <= nums.length+2; i++) {
            if(((i >> x) & 1) == 1) {
                x1 ^= i;
            }
            if(k < nums.length && ((nums[k] >> x) & 1) == 1) {
                x1 ^= nums[k];
                k++;
            }
            if(((i >> x) & 1) == 0) {
                x2 ^= i;
            }
            if(k < nums.length && ((nums[k] >> x) & 1) == 0) {
                x2 ^= nums[k];
                k++;
            }
        }
        ret[0] = x2;
        ret[1] = x1;
        return ret;
    }

    public static void main(String[] args) {
        int[] array = {1, 2, 3, 5, 7, 8, 9, 10};
        int[] ret = missingTwo(array);
        System.out.println(Arrays.toString(ret));
    }
}